<template>
	<view class="template-preferred tn-safe-area-inset-bottom">

		<!-- 顶部自定义导航 -->

		<!-- 顶部自定义导航 -->
		<tn-nav-bar fixed alpha customBack>
			<view slot="back" class='tn-custom-nav-bar__back' @click="goBack">
				<text class='icon tn-icon-left'></text>
				<text class='icon tn-icon-home-capsule-fill'></text>
			</view>
		</tn-nav-bar>
		<view class="">



			<view class="tn-flex  tn-margin-top-xl">
				<view class=" tn-margin tn-text-bold tn-text-xl">
					健康食谱
				</view>

			</view>


			<!-- 页面内容 -->
			<view>
				<view class="tn-padding-sm">
					<tn-waterfall ref="waterfall" v-model="data" @finish="handleWaterFallFinish">
						<template v-slot:left="{ leftList }">
							<view v-for="(item, index) in leftList" :key="item.id" class="product__item"
								@click="tn('/pages/main/tabbar/tabbar-2/preferred_info?id=' + item.id)">
								<view class="item__image">
									<tn-lazy-load :threshold="-450" height="100%" :image="item.mainImage"
										:index="item.id" imgMode="widthFix"></tn-lazy-load>
								</view>
								<view class="item__data">
									<view class="item__title-container">
										
										<text class="item__title">{{ item.title }}</text>
									</view>
									<view v-if="item.tags && item.tags.length > 0" class="item__tags-container">
										<view v-for="(tagItem, tagIndex) in item.tags" :key="tagIndex"
											class="item__tag">{{ tagItem }}</view>
									</view>
									<view class="item__price-container ">
										<text class="item__price--integer">{{ item.name }}</text>
										
									</view>
								</view>
							</view>
						</template>
						<template v-slot:right="{ rightList }">
							<view v-for="(item, index) in rightList" :key="item.id" class="product__item"
								 @click="tn('/pages/main/tabbar/tabbar-2/preferred_info?id=' + item.id)">
								<view class="item__image">
									<tn-lazy-load :threshold="-450" height="100%" :image="item.mainImage"
										:index="item.id" imgMode="widthFix"></tn-lazy-load>
								</view>
								<view class="item__data">
									<view class="item__title-container">
										
										<text class="item__title">{{ item.title }}</text>
									</view>
									<view class="item__tags-container">
										<view v-for="(tagItem, tagIndex) in item.tags" :key="tagIndex"
											class="item__tag">{{ tagItem }}</view>
									</view>
									<view class="item__price-container ">
										<text class="item__price--integer">{{ item.name }}</text>
										
									</view>
								</view>
							</view>
						</template>
					</tn-waterfall>
				</view>

				<tn-load-more :status="loadStatus"></tn-load-more>


			</view>

		</view>


		<view class='tn-tabbar-height'></view>

	</view>
</template>

<script>
	import template_page_mixin from '@/libs/mixin/template_page_mixin.js'
	export default {
		name: 'Preferred',
		name: 'TemplateDetails',
		mixins: [template_page_mixin],
		data() {
			return {


				loadStatus: 'loadmore',

				data: []
			}
		},
		mounted() {
			this.getData()
		},
		// onReachBottom() {
		//   this.getRandomData()
		// },

		methods: {
			getData() {
				uni.request({
					url: 'https://xq.michuang.top/api/index/getFoodList',
					method: 'POST',
					data: {
						
					},
					success: (res) => {
						if (res.data) {
							// 成功获取数据
							// 更新轮播图数据
							console.log(res.data.data)
							this.data = res.data.data;
						} else {
							// 处理请求失败的情况
							console.error('接口请求失败');
						}
					},
					fail: (err) => {
						// 处理请求失败的情况
						console.error('接口请求失败', err);
					}
				});
			},
			// cardSwiper
			cardSwiper(e) {
				this.cardCur = e.detail.current
			},
			// tab选项卡切换
			tabChange(index) {
				this.current = index
			},
			// 跳转
			tn(e) {
				uni.navigateTo({
					url: e,
				});
			},

			// 瀑布流加载完毕事件
			handleWaterFallFinish() {
				this.loadStatus = 'loadmore'
			},

		}
	}
</script>

<style lang="scss" scoped>
	.template-preferred {
		// background-color: $tn-bg-gray-color;
		max-height: 100vh;
	}

	.tn-tabbar-height {
		min-height: 120rpx;
		height: calc(140rpx + env(safe-area-inset-bottom) / 2);
	}

	.tn-custom-nav-bar__back {
		width: 100%;
		height: 100%;
		position: relative;
		display: flex;
		justify-content: space-evenly;
		align-items: center;
		box-sizing: border-box;
		background-color: rgba(0, 0, 0, 0.15);
		border-radius: 1000rpx;
		border: 1rpx solid rgba(255, 255, 255, 0.5);
		color: #FFFFFF;
		font-size: 18px;

		.icon {
			display: block;
			flex: 1;
			margin: auto;
			text-align: center;
		}

		&:before {
			content: " ";
			width: 1rpx;
			height: 110%;
			position: absolute;
			top: 22.5%;
			left: 0;
			right: 0;
			margin: auto;
			transform: scale(0.5);
			transform-origin: 0 0;
			pointer-events: none;
			box-sizing: border-box;
			opacity: 0.7;
			background-color: #FFFFFF;
		}
	}


	/* 瀑布流商品*/
	.product__item {
		background-color: #FFFFFF;
		border-radius: 15rpx;
		overflow: hidden;
		margin: 0 15rpx 30rpx 15rpx;
		box-shadow: 0rpx 0rpx 30rpx 0rpx rgba(0, 0, 0, 0.07);

		.item {

			/* 图片 start */
			&__image {
				width: 100%;
				height: auto;
				background-color: #FFFFFF;
			}

			/* 图片 end */

			/* 内容 start */
			&__data {
				padding: 20rpx 20rpx;
			}

			/* 标题 start */
			&__title-container {
				text-align: justify;
				line-height: 38rpx;
				vertical-align: middle;
			}

			&__store-type {
				height: 28rpx;
				font-size: 20rpx;
				position: relative;
				display: inline-flex;
				align-items: center;
				justify-content: center;
				padding: 0 4rpx;
				border-radius: 6rpx;
				white-space: nowrap;
				text-align: center;
				top: -2rpx;
				margin-right: 6rpx;
			}

			&__title {}

			/* 标题 end */

			/* 标签 start */
			&__tags-container {
				display: flex;
				flex-direction: row;
				flex-wrap: nowrap;
				align-items: center;
				justify-content: flex-start;
			}

			&__tag {
				margin: 10rpx;
				color: #FF7043;
				border: 2rpx solid #FF7043;
				padding: 0 6rpx;
				border-radius: 10rpx;
				font-size: 20rpx;

				&:first-child {
					margin-left: 0rpx !important;
				}
			}

			/* 标签 end */

			/* 价格 start */
			&__price-container {
				padding: 10rpx 0;
				font-size: 24rpx;
				font-weight: bold;
				
			}

			&__price {
				&--unit {}

				&--integer {
					font-size: 38rpx;
				}

				&--decimal {}
			}

			/* 价格 end */
			/* 内容 end */
		}
	}
</style>